home *** CD-ROM | disk | FTP | other *** search
- /*
- % RLE_Write . C
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- This software is copyright (C) by the Lawrence Berkeley Laboratory.
- Permission is granted to reproduce this software for non-commercial
- purposes provided that this notice is left intact.
-
- It is acknowledged that the U.S. Government has rights to this software
- under Contract DE-AC03-765F00098 between the U.S. Department of Energy
- and the University of California.
-
- This software is provided as a professional and academic contribution
- for joint exchange. Thus, it is experimental, and is provided ``as is'',
- with no warranties of any kind whatsoever, no support, no promise of
- updates, or printed documentation. By using this software, you
- acknowledge that the Lawrence Berkeley Laboratory and Regents of the
- University of California shall have no liability with respect to the
- infringement of other copyrights by any part of this software.
-
- For further information about this notice, contact William Johnston,
- Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
- (wejohnston@lbl.gov)
-
- For further information about this software, contact:
- Jin Guojun
- Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
- g_jin@lbl.gov
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % AUTHOR: Jin Guojun - LBL 12/1/91
- */
-
- #ifndef RLE_IMAGE
- #define RLE_IMAGE
- #endif
-
- #if !defined LKT && !defined FLOAT_LKT_REQUIRED
- #define LKT int /* for window application */
- #endif
-
- #include "header.def"
- #include "imagedef.h"
-
- write_rle(img, lkt, mapped /* from src to dest */)
- U_IMAGE *img;
- LKT *lkt;
- {
- register int i, j, ch;
- byte *pp[3], *dp[3];
- int w, h, X0=0;
-
- if (img->sub_img)
- w = img->sub_img_w,
- h = img->sub_img_h,
- X0 = img->sub_img_x;
- else w =img->width, h = img->height;
-
- rle_dflt_hdr.rle_file = img->OUT_FP;
- if (lkt) {
- dp[0] = (byte*) zalloc(w*3, sizeof(*dp[0]), "dp");
- dp[1] = dp[0] + w;
- dp[2] = dp[1] + w;
- }
- rle_dflt_hdr.xmin = rle_dflt_hdr.ymin = 0;
- rle_dflt_hdr.xmax = w - 1;
- rle_dflt_hdr.ymax = h - 1;
- rle_dflt_hdr.ncolors = img->dpy_channels;
- if (img->color_form==CFM_SCF) /* if not mapped, cmap is in reg */
- regmap_to_rlemap(img->cmap ? img->cmap : reg_cmap,
- img->cmaplen, 3, &rle_dflt_hdr);
- else rle_dflt_hdr.ncmap = rle_dflt_hdr.cmaplen =
- (int)(rle_dflt_hdr.cmap = NULL); /* must be 0 ! */
- rle_put_setup(&rle_dflt_hdr);
-
- for (i=0; i<h; i++) {
- if (mapped)
- pp[0] = SAVED_RLE_ROW(img, (img->sub_img ?
- img->sub_img_y+img->sub_img_h : img->height) - i) + X0;
- else
- pp[0] = ORIG_RLE_ROW(img, (img->sub_img ?
- img->sub_img_y+img->sub_img_h : img->height) - i) + X0;
- pp[1] = pp[0] + img->width;
- pp[2] = pp[1] + img->width;
- if (lkt) {
- for (ch=0; ch<img->channels; ch++) {
- register LKT *lktp = lkt + ch*MaxColors;
- if (img->update && img->sub_img)
- memcpy(dp[ch], pp[ch], w);
- else
- for (j=0; j<w; j++)
- dp[ch][j] = lktp[pp[ch][j]];
- }
- rle_putrow(dp, w, &rle_dflt_hdr);
- }
- else rle_putrow(pp, w, &rle_dflt_hdr);
- }
- rle_puteof(&rle_dflt_hdr); /* for multi-frame images only */
-
- if (lkt) free(dp[0]);
- img->update = False;
- }
-